*12-01-25_Dafoe_Russett_Democracy_Capitalism

***This document contains the code for the following work. 

*If you use this code, please cite:
*Dafoe, Allan and Bruce Russett. 2012. Democracy and Capitalism: Interwoven Strands of the Liberal Peace. in Eds. Nils Petter Gleditsch and Gerald Schneider. The Capitalist Peace. 

*and also cite the chapter that this work responds to and from which much of the code and data comes: 

*Mousseau, Michael, Omer F. Orsue, Jameson L. Ungerer, and Demet Y. Mousseau. 2012. Capitalism and Peace: It's Keynes, not Hayek. in Eds. Nils Petter Gleditsch and Gerald Schneider. The Capitalist Peace. 


*****************************************************************************
**************Operationalizations of Dyadic Democracy************************
*****************************************************************************

*see files in "Dafoe_Russett_2013_ISQ_Repfiles"



*****************************************************************************
****************************Set Up*******************************************
*****************************************************************************

log using "12-09-18_DR_log.log", replace

clear



set more off

global filetree /Users/Allan/Dropbox/!!Papers/Liberal Peace/11-12-21_Commentary_on_Mousseau/Replication Files/

cd "$filetree"

do "12-01-25_Moum2012build.do"

cd "$filetree"
save "MOUM2012-2.dta", replace

clear
cd "$filetree"
use "MOUM2012-2.dta"

label variable peaceyrs "Time Since Last Crisis"



*****************************************************************************
**************Including DemocracyHigh Instead of Regime Difference***********
*****************************************************************************

global controlvars  lncprt  majpow cntgd dist  numstate  peaceyrs _spline1 _spline2 _spline3


***MOUM 2012 original TABLE 1: CIE, DEMOCRACY AND ICB ONSET, 1960-2001
*replicated precisely
quietly {
eststo clear
*Table 1, Model 1
eststo: logit 		crisis1 	   		  dml   dmdist 			  $controlvars if CIEl!=., cl(dyadid) nolog
*Table 1, Model 2
eststo: logit 		crisis1 		CIEl  dml   dmdist 			  $controlvars, cl(dyadid) nolog
*Table 1, Model 3
eststo: logit 		crisis1 		CIEl  bdm   dmdist			  $controlvars, cl(dyadid) nolog
*Table 1, Model 4
eststo: logit 		crisis1 		CIEl  dm10  dmdist			  $controlvars, cl(dyadid) nolog
*Table 1, Model 5
eststo: logit 		crisis1         CIEl  dmlsq 	dmdist			  $controlvars, cl(dyadid) nolog
*Table 1, Model 6
eststo: logit 		crisis1 		CIEl  	                      $controlvars, cl(dyadid) nolog
}
esttab, b(2) se(2) replace label star(`=char(160)' 0.10 * 0.05 ** 0.01 *** 0.001)  order(CIEl dml bdm dmlsq dmdist $controlvars) scalars("ll Log lik.") pr2 varwidth(25) modelwidth(8)

*Note that the stars are modified to correspond with Goldstein's (2010) recommendation.

***Dafoe & Russett 2012 Table A1 (exact same table as above, but now with dmh instead of dmdist)

quietly {
eststo clear
*Table 1, Model 1
eststo: logit 		crisis1 	   		  dml   dmh 			  $controlvars if CIEl!=., cl(dyadid) nolog
*Table 1, Model 2
eststo: logit 		crisis1 		CIEl  dml   dmh 			  $controlvars, cl(dyadid) nolog
*Table 1, Model 3
eststo: logit 		crisis1 		CIEl  bdm   dmh			  $controlvars, cl(dyadid) nolog
*Table 1, Model 4
eststo: logit 		crisis1 		CIEl  dm10  dmh			  $controlvars, cl(dyadid) nolog
*Table 1, Model 5
eststo: logit 		crisis1         CIEl  dmlsq 	dmh			  $controlvars, cl(dyadid) nolog
*Table 1, Model 6
eststo: logit 		crisis1 		CIEl  	                      $controlvars, cl(dyadid) nolog
}
esttab using TableA1.rtf, b(2) se(2) replace label star(`=char(160)' 0.10 * 0.05 ** 0.01 *** 0.001)  order(CIEl dml bdm dmlsq dmh $controlvars) scalars("ll Log lik.") pr2 varwidth(25) modelwidth(8)



*****************************************************************************
**************Interacting CIEl and DemocracyLow******************************
*****************************************************************************

***Clarify Interaction
**The following code based on:
*Michael Tomz, Jason Wittenberg, and Gary King. 2003. CLARIFY: Software for Inter- preting and Presenting Statistical Results. Version 2.1. Stanford University, University of Wisconsin, and Harvard University. January 5. Available at http://gking.harvard.edu/


****Figure 1
clear

cd "$filetree"

use "MOUM2012-2.dta"

global controlvars  lncprt  majpow cntgd dist  numstate  peaceyrs _spline1 _spline2 _spline3


***Using Model 2 from MOUM Table 1
estsimp logit 		crisis1 		CIEl  dml  CIElDml dmdist 			  $controlvars, cl(dyadid) nolog sims(10000)

summarize dml, d
   local mx1=r(p50)
   local mx2=r(p90)
   *These will be used to change democracy from median to 90th percentile (50 to 90th percentile). This assumes holding the difference in democracy constant. 
   
   
sum CIEl,d
local min=r(min) 
*r(p10)
local max=r(max) 
*r(p90)
   
 gen plo=.
   gen phi=.
   gen plo1=.
   gen phi1=.
   gen plo2=.
   gen phi2=.
   gen pmid=.
   gen pmid1=.
   gen pmid2=.
   gen pidifflo=.
   gen pidiffhi=.
   gen pidiffmed=.
   gen frequency=.
   
local numbersteps=61
   generate xaxis = `min'+ (_n-1)*(`max'-`min')/(`numbersteps'-1) in 1/`numbersteps'
   
   local span=(`max'-`min')/(`numbersteps'-1)

*   generate CIElaxis = round((_n-1)/10,0.1) in 1/61
setx lncprt median  majpow 0 cntgd 1 dist min  numstate median  peaceyrs 0 _spline1 0 _spline2 0 _spline3 0

gen zero=0 if xaxis~=.


local a = 1
while `a' <= `numbersteps' {
   setx CIEl xaxis[`a'] dml `mx1' CIElDml xaxis[`a']*`mx1'
      simqi, prval(1) genpr(pi1)

   setx CIEl xaxis[`a'] dml `mx2' CIElDml xaxis[`a']*`mx2'
   simqi, prval(1) genpr(pi2) 
	
	gen pidiff=pi2-pi1
	_pctile pidiff, p(2.5, 50, 97.5)
	replace pidifflo= r(r1) if `a'==_n
	replace pidiffmed=r(r2) if `a'==_n
	replace pidiffhi=r(r3) if `a'==_n
	
	
    if `a'==1 { 
    count if CIEl<=xaxis[`a']+`span'/2
    replace frequency=r(N) if _n==`a'
    }
    if `a'>1 & `a'<`numbersteps' {
    count if CIEl>xaxis[`a']-`span'/2 & CIEl<=xaxis[`a']+`span'/2 & CIEl~=.
    replace frequency=r(N) if _n==`a'
    }
    if `a'==`numbersteps' {
    count if CIEl>xaxis[`a']-`span'/2 & CIEl~=.
    replace frequency=r(N) if _n==`a'    
    }

	
drop pi1 pi2 pidiff
   local a = `a' + 1
}


order xaxis pidiff*

sort xaxis

sum pidiffhi, d
local toprange=0.0012
local xrange=6

sort xaxis


twoway  (rarea pidifflo pidiffhi xaxis if xaxis < `xrange',  lcolor(white)) ||  (line pidiffmed xaxis if xaxis < `xrange', lpattern(solid) lwidth(thick) ) || (line pidifflo xaxis if xaxis < `xrange', lpattern(solid) lwidth(thin)) || (line pidiffhi xaxis if xaxis < `xrange', lpattern(solid) lwidth(thin)) || (kdensity CIEl,	xaxis(2) yaxis(2)	xscale(axis(2) off) yscale(axis(2) range(0 `max_len'/5)) ),  xtitle(ln(LIFE INSURANCE PREMIUMS/CAPITA)) ytitle("Change in P(CRISIS)", axis(1)) ytitle("", axis(2))   yscale(range(-0.002 0.001)) title(Predicted Effect of DEMOCRACY (LOW) (Both-Counterfactual))  legend(order(1 "95% CI" 2 "Estimated" "Effect" 5 "Density"))  yline(0,lp(solid) lwidth(medthick)) scheme(lean2) 

graph export interaction_dmlbw.pdf, replace
graph export interaction_dmlbw.png, replace


twoway  (rarea pidifflo pidiffhi xaxis if xaxis < `xrange',  lcolor(white)) ||  (line pidiffmed xaxis if xaxis < `xrange', lpattern(solid) lwidth(thick) ) || (kdensity CIEl,	xaxis(2) yaxis(2)	xscale(axis(2) off ) yscale(axis(2) range(0 `max_len'/5))),  xtitle(ln(LIFE INSURANCE PREMIUMS/CAPITA))  ytitle("Change in P(CRISIS)", axis(1)) ytitle("", axis(2))   yscale(range(-0.002 0.001)) title(Predicted Effect of DEMOCRACY (LOW) (Both-Counterfactual))  legend(order(1 "95% CI" 2 "Estimated" "Effect" 3 "Density"))  yline(0,lp(solid) lwidth(medthick)) 

graph export interaction_dmlcol.pdf, replace
graph export interaction_dmlcol.png, replace


*Significance at about CIEl=1.3
count if CIEl<1.3
local A1= r(N)
count if CIEl~=.
local A2= r(N)
di `A1'/`A2'
*68% insignificant; 32% significant. 

*******


***Figure 2

clear
cd "$filetree"
use "MOUM2012-2.dta"

global controlvars  lncprt  majpow cntgd dist  numstate  peaceyrs _spline1 _spline2 _spline3


estsimp logit 		crisis1 		CIEl  dml  CIElDml dmh 			  $controlvars, cl(dyadid) nolog sims(10000)

summarize dml, d
   local mx1=r(p50)
   local mx2=r(p90) 
   
sum CIEl,d
local min=r(min) 
*r(p10)
local max=r(max) 
*r(p90)
   
 gen plo=.
   gen phi=.
   gen plo1=.
   gen phi1=.
   gen plo2=.
   gen phi2=.
   gen pmid=.
   gen pmid1=.
   gen pmid2=.
   gen pidifflo=.
   gen pidiffhi=.
   gen pidiffmed=.
   gen frequency=.
   
local numbersteps=61
   generate xaxis = `min'+ (_n-1)*(`max'-`min')/(`numbersteps'-1) in 1/`numbersteps'
   
   local span=(`max'-`min')/(`numbersteps'-1)

*   generate CIElaxis = round((_n-1)/10,0.1) in 1/61

setx lncprt median  majpow 0 cntgd 1 dist min  numstate median  peaceyrs 0 _spline1 0 _spline2 0 _spline3 0

gen zero=0 if xaxis~=.


local a = 1
while `a' <= `numbersteps' {
   setx CIEl xaxis[`a'] dml `mx1' CIElDml xaxis[`a']*`mx1'
      simqi, prval(1) genpr(pi1)

   setx CIEl xaxis[`a'] dml `mx2' CIElDml xaxis[`a']*`mx2'
   simqi, prval(1) genpr(pi2) 
	
	gen pidiff=pi2-pi1
	_pctile pidiff, p(2.5, 50, 97.5)
	replace pidifflo= r(r1) if `a'==_n
	replace pidiffmed=r(r2) if `a'==_n
	replace pidiffhi=r(r3) if `a'==_n
	
	
    if `a'==1 { 
    count if CIEl<=xaxis[`a']+`span'/2
    replace frequency=r(N) if _n==`a'
    }
    if `a'>1 & `a'<`numbersteps' {
    count if CIEl>xaxis[`a']-`span'/2 & CIEl<=xaxis[`a']+`span'/2 & CIEl~=.
    replace frequency=r(N) if _n==`a'
    }
    if `a'==`numbersteps' {
    count if CIEl>xaxis[`a']-`span'/2 & CIEl~=.
    replace frequency=r(N) if _n==`a'    
    }

	
drop pi1 pi2 pidiff
   local a = `a' + 1
}


order xaxis pidiff*

sort xaxis

twoway  (rarea pidifflo pidiffhi xaxis if xaxis < `xrange',  lcolor(white)) ||  (line pidiffmed xaxis if xaxis < `xrange', lpattern(solid) lwidth(thick)) || (line pidifflo xaxis if xaxis < `xrange', lpattern(solid) lwidth(thin)) || (line pidiffhi xaxis if xaxis < `xrange', lpattern(solid) lwidth(thin)) || (kdensity CIEl,	xaxis(2) yaxis(2)	xscale(axis(2) off )		yscale(axis(2) range(0 `max_len'/5))),   xtitle(ln(LIFE INSURANCE PREMIUMS/CAPITA)) ytitle("Change in P(CRISIS)", axis(1)) ytitle("", axis(2))   yscale(range(-0.002 0.001)) title(Predicted Effect of DEMOCRACY (LOW) (Lowest-Counterfactual))  legend(order(1 "95% CI" 2 "Estimated" "Effect" 5 "Density" ))  yline(0,lp(solid) lwidth(medthick)) scheme(lean2)

graph export interaction_dml2bw.pdf, replace
graph export interaction_dml2bw.png, replace

twoway  (rarea pidifflo pidiffhi xaxis if xaxis < `xrange',  lcolor(white)) ||  (line pidiffmed xaxis if xaxis < `xrange', lpattern(solid) lwidth(thick)) || (kdensity CIEl,	xaxis(2) yaxis(2)	xscale(axis(2) off )		yscale(axis(2) range(0 `max_len'/5))),   xtitle(ln(LIFE INSURANCE PREMIUMS/CAPITA)) ytitle("Change in P(CRISIS)", axis(1)) ytitle("", axis(2))  yscale(range(-0.002 0.001)) title(Predicted Effect of DEMOCRACY (LOW) (Lowest-Counterfactual))  legend(order(1 "95% CI" 2 "Estimated" "Effect" 3 "Density" ))  yline(0,lp(solid) lwidth(medthick)) 

graph export interaction_dml2col.pdf, replace
graph export interaction_dml2col.png, replace




**
*Significance at about CIEl=0.5
count if CIEl<0.5
local A1= r(N)
count if CIEl~=.
local A2= r(N)
di `A1'/`A2'
di (`A2'-`A1')/`A2'
*33% insignificant; 67% significant. 



*****Figure A1

clear
cd "$filetree"
use "MOUM2012-2.dta"

global controlvars  lncprt  majpow cntgd dist  numstate  peaceyrs _spline1 _spline2 _spline3



estsimp logit 		crisis1 		CIEl  dml  CIElDml dmdist 			  $controlvars, cl(dyadid) nolog sims(10000)

summarize CIEl, d
   local mx1=round(r(p50),0.001)
   local mx2=round(r(p90),0.001)
   *These will be used to change CIEl from median to 90th percentile (50 to 90th percentile). 

sum dml,d
local dmlmin=r(min)
   generate dmlaxis = `dmlmin'+_n-1 in 1/21

   
 gen plo=.
   gen phi=.
   gen plo1=.
   gen phi1=.
   gen plo2=.
   gen phi2=.
   gen pmid=.
   gen pmid1=.
   gen pmid2=.
   gen pidifflo=.
   gen pidiffhi=.
   gen pidiffmed=.

setx lncprt median  majpow 0 cntgd 1 dist min  numstate median  peaceyrs 0 _spline1 0 _spline2 0 _spline3 0

local a = 0
while `a' <= 21 {
   setx dml `a'-10 CIEl `mx1' CIElDml ((`a'-10)*`mx1')
   simqi, prval(1) genpr(pi1) 

   setx dml `a'-10 CIEl `mx2' CIElDml ((`a'-10)*`mx2')
   simqi, prval(1) genpr(pi2) 
	
	gen pidiff=pi2-pi1
	_pctile pidiff, p(2.5, 50, 97.5)
	replace pidifflo=r(r1) if dmlaxis==`a'-10
	replace pidiffmed=r(r2) if dmlaxis==`a'-10
	replace pidiffhi=r(r3) if dmlaxis==`a'-10
	
drop pi1 pi2 pidiff
   local a = `a' + 1
}


order dmlaxis pidiff*

sort dmlaxis


twoway  (rarea pidifflo pidiffhi dmlaxis,  lcolor(white)) ||  (line pidiffmed dmlaxis, lpattern(solid) lwidth(thick)) || (line pidifflo dmlaxis, lpattern(solid) lwidth(thin)) || (line pidiffhi dmlaxis, lpattern(solid) lwidth(thin)) || (kdensity dml,	xaxis(2) yaxis(2)	xscale(axis(2) off )		yscale(axis(2) range(0 `max_len'/1.5))),  ymtick(##10)  xtitle(DEMOCRACY (LOW)) ytitle("Change in P(CRISIS)", axis(1)) ytitle("", axis(2))   xmtick(##5) title(Contract Intensive Economy (Low) and Conflict)  legend(order(1 "95% CI" 2 "Estimated" "Effect" 5 "Density")) yline(0,lp(solid) lwidth(medthick)) scheme(lean2)
graph export interaction_CIEbw.pdf, replace
graph export interaction_CIEbw.png, replace

twoway  (rarea pidifflo pidiffhi dmlaxis,  lcolor(white)) ||  (line pidiffmed dmlaxis, lpattern(solid) lwidth(thick)) || (kdensity dml,	xaxis(2) yaxis(2)	xscale(axis(2) off )		yscale(axis(2) range(0 `max_len'/1.5))),  ymtick(##10)  xtitle(DEMOCRACY (LOW)) ytitle("Change in P(CRISIS)", axis(1)) ytitle("", axis(2))   xmtick(##5) title(Contract Intensive Economy (Low) and Conflict)  legend(order(1 "95% CI" 2 "Estimated" "Effect" 3 "Density")) yline(0,lp(solid) lwidth(medthick)) 


graph export interaction_CIEcol.pdf, replace
graph export interaction_CIEcol.png, replace

   
count if dml<-7
local A1= r(N)
count if dml~=.
local A2= r(N)
di `A1'/`A2'
di 129632/405126





*****************************************************************************
*******************************Adding CIEh***********************************
*****************************************************************************

clear
cd "$filetree"
use "MOUM2012-2.dta"


***MOUM TABLE 1, with CIEh included
quietly {
eststo clear
*Table 1, Model 1
eststo: logit 		crisis1 	   		  dml   dmdist 			  $controlvars if CIEl!=., cl(dyadid) nolog
*Table 1, Model 2
eststo: logit 		crisis1 		CIEl CIEh  dml   dmdist 			  $controlvars, cl(dyadid) nolog
*Table 1, Model 3
eststo: logit 		crisis1 		CIEl CIEh bdm   dmdist			  $controlvars, cl(dyadid) nolog
*Table 1, Model 4
eststo: logit 		crisis1 		CIEl CIEh dm10  dmdist			  $controlvars, cl(dyadid) nolog
*Table 1, Model 5
eststo: logit 		crisis1         CIEl CIEh dmlsq 	dmdist			  $controlvars, cl(dyadid) nolog
*Table 1, Model 6
eststo: logit 		crisis1 		CIEl CIEh 	                      $controlvars, cl(dyadid) nolog
}
esttab using Table1.rtf, b(2) se(2) replace label star(`=char(160)' 0.10 * 0.05 ** 0.01 *** 0.001)  order(CIEl CIEh dml bdm dmlsq dmdist $controlvars) scalars("ll Log lik.") pr2 varwidth(25) modelwidth(8)



*****************************************************************************
**********************Looking at Polity=10***********************************
*****************************************************************************

*Data for Mousseau 2009 acquired from Michael Mousseau. 
clear
cd "$filetree"
use "Mousseau_IS_2009.dta"

gen bCIE=0 if CIE1~=. & CIE2~=.
replace bCIE=1 if  CIE1+CIE2==2
replace bCIE=. if CIE1==. | CIE2==.

gen dml=polity21 if polity21<= polity22 & polity21~=. & polity22~=.
replace dml= polity22 if polity21> polity22 & polity21~=. & polity22~=.
replace dml=. if polity21==. | polity22==.
   
count if bCIE==1 & dml~=.
local A1= r(N)
count if bCIE~=. & dml~=.
local A2= r(N)
di `A1'/`A2'
*3.8% of dyads have bCIE=1; or 10866/287126


count if dml==10 & bCIE~=.
local A1= r(N)
count if dml~=. & bCIE~=.
local A2= r(N)
di `A1'/`A2'
*3.7% of dyads have polity=10; or 10587/287126

count if dml>=7 & dml~=. & bCIE~=.
local A1= r(N)
count if dml~=. & bCIE~=.
local A2= r(N)
di `A1'/`A2'
*12.4% of dyads have polity>=7; or 35729/287126

log close

